'''
Created on 2014-5-5

@author: shen
'''
from read_list_from_file  import read_price_list_WomenJeans as read_price_list
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt


# Example data
if __name__ == '__main__':
   price = ('0-20', '20-50',  '50-100','100-150','150-200','200-?')
   y_pos = np.arange(len(price))
   performance=[0,0,0,0,0,0]

   readinfo=read_price_list.Get_Price_List()
   list=[]
   list=readinfo.get_infolist()
   times=[]
   for number in range(0,len(list))  :
        ifhas=0
        for x in range(0,len(times)):
            if(list[number]['time'].split(' ')[0]==times[x]):
                ifhas=1
                break
        if(ifhas==0):
            times.append(list[number]['time'].split(' ')[0])
   for  i in range(0,len(times)-1):
        for j in range(0,len(times)-1):
            if(times[j]>times[j+1]):
                x=times[j]
                times[j]=times[j+1]
                times[j+1]=x
    
   for i in range(0,len(times)):
       performance=[0,0,0,0,0,0]
       for number in range(0,len(list))  :
         if(list[number]['time'].split(' ')[0]==times[i]):  
            if(list[number]['price']<=20):  performance[0]=performance[0]+1
            if(list[number]['price']>20 and list[number]['price']<=50 ):  performance[1]=performance[1]+1
            if(list[number]['price']>50 and list[number]['price']<=100):  performance[2]=performance[2]+1
            if(list[number]['price']>100 and list[number]['price']<=150):  performance[3]=performance[3]+1
            if(list[number]['price']>150 and list[number]['price']<=200):  performance[4]=performance[4]+1
            if(list[number]['price']>200 ):  performance[5]=performance[5]+1
   
   
       error = np.random.rand(len(price))
       plt.barh(y_pos, performance, xerr=error, align='center', alpha=0.4)
       plt.yticks(y_pos, price)
       plt.xlabel('Numbers')
       plt.title('Price Distribution Of WomenJeans_'+times[i])
#        plt.subplot(320+i)
       plt.show()
      
 